﻿using EOS.DataModel;
using EOS.IDAL;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EOS.DAL
{
    public  class TestRepository:CommonRepository<List<UserInfo>> , ITestRepository
    {
        public void UpdateUserInfo(List<UserInfo> infoList)
        {
            this.ExecuteByTrans(infoList, this.UpdateInfo);
        }

        private void UpdateInfo(List<UserInfo> infoList)
        {
            StringBuilder sql = new StringBuilder();
            for (int i = 0; i <= infoList.Count - 1; i++)
            {
                var parameter = new List<DbParameter>();
                UserInfo info = infoList[i];
                sql = new StringBuilder();
                sql.AppendLine("update UserInfo set");
                sql.AppendLine(" UName = @UName");
                sql.AppendLine(" ,SubTime = @SubTime");
                sql.AppendLine(" where ID = @ID ");
                parameter.Add(ConvertExtension.CreateDbParameter("@UName", info.UName));
                parameter.Add(ConvertExtension.CreateDbParameter("@SubTime", info.SubTime));
                parameter.Add(ConvertExtension.CreateDbParameter("@ID", info.ID));
                this.ExecuteBySql(sql.ToString(), parameter.ToArray());
            }
        }
        public void ExcuteProc(List<UserInfo> infoList)
        {
            this.BeginTrans();
            try
            {
                for (int i = 0; i <= infoList.Count - 1; i++)
                {
                    var parameter = new List<DbParameter>();
                    UserInfo info = infoList[i];

                    parameter.Add(ConvertExtension.CreateDbParameter("@id", info.ID));
                    parameter.Add(ConvertExtension.CreateDbParameter("@uname", info.UName));
                    parameter.Add(ConvertExtension.CreateDbParameter("@subtime", info.SubTime));
                    parameter.Add(ConvertExtension.CreateDbParameter("@count", "-1"));

                    int count1 = this.ExecuteByProc("PROC_UPDATE", parameter.ToArray());
                }
                this.Commit();
            }
            catch (Exception)
            {
                this.Rollback();
                throw;
            }
        }
    }
}
